<%--
  Created by IntelliJ IDEA.
  User: mengshun
  Date: 2022/3/17
  Time: 16:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>登录页</title>
</head>
<body>
    <%
            String username = null;
            String password=null;
            String rem  = null;
            //获取浏览器的缓存  cookie
           Cookie[] cookies = request.getCookies();
           //遍历cookie  查找 用户名和密码存储的cookie
            if(cookies!=null){ //判定是否是第一次请求  避免空指针
                for (Cookie cookie : cookies) {

                    if(cookie.getName().equals("username")){
                        username = cookie.getValue();
                    }
                    if(cookie.getName().equals("password")){
                        password= cookie.getValue();
                    }
                    if(cookie.getName().equals("rem")){
                        rem  = cookie.getValue();
                    }

                }
            }

    %>
    <h1>欢迎登录</h1>
    <form action="login" method="post">
        <p><input type="text" name="username" placeholder="请输入用户名" value="<%=username==null?"":username%>"></p>
        <p><input type="password" name="password" placeholder="请输入密码" value="<%=password==null?"":password%>"></p>
        <p><input type="checkbox"   name="rem" value="true" <%="true".equals(rem)?"checked":""%>>记住我</p>
        <p><input type="submit" value="立即登录"></p>
    </form>
     <span><%=request.getAttribute("info")==null?"":request.getAttribute("info")%></span>
</body>
</html>
